package com.fjwt.gz.service.activity.platform.acte017;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fjwt.gz.components.mq.model.Acte017SendCouponMQ;
import com.fjwt.gz.components.mq.model.ExportExcelMQ;
import com.fjwt.gz.components.mq.vender.IMQSender;
import com.fjwt.gz.core.cache.RedisUtil;
import com.fjwt.gz.core.constants.ApiCodeEnum;
import com.fjwt.gz.core.constants.Constants;
import com.fjwt.gz.core.exception.BizException;
import com.fjwt.gz.core.utils.AmountUtil;
import com.fjwt.gz.core.utils.ApiStatisticsLogger;
import com.fjwt.gz.db.bo.ActivityAwardAndSettingBo;
import com.fjwt.gz.db.bo.ActivityUserTimesBO;
import com.fjwt.gz.db.dto.FansActivityDTO;
import com.fjwt.gz.db.entity.*;
import com.fjwt.gz.db.vo.ActivityAwardVO;
import com.fjwt.gz.service.activity.BaseActivityService;
import com.fjwt.gz.service.impl.*;
import com.fjwt.gz.service.mapper.StatActe017RecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * ------ 越减越便宜升级版【郑州版】
 */
@Slf4j
@Service
public class ACTE017Service extends BaseActivityService<Object> {

    @Autowired
    private ActivityAwardService activityAwardService;
    @Autowired
    private FansAwardService fansAwardService;
    @Autowired
    private AwardSettingService awardSettingService;
    @Autowired
    private ActivitySettingService activitySettingService;
    @Autowired
    private SendAwardService sendAwardService;
    @Autowired
    private ActivityService activityService;
    @Autowired
    private FansActivityService fansActivityService;
    @Autowired
    private FansAuthService fansAuthService;
    @Autowired
    private AgentInfoService agentInfoService;
    @Autowired
    private IMQSender mqSender;
    @Autowired
    private SysExportTaskService sysExportTaskService;
    @Autowired
    private StatActe017RecordMapper statActe017RecordMapper;
    @Autowired
    private ConsumeThread consumeThread;
    @Autowired
    private StatActe017NumService statActe017NumService;

    private static String queuePrefix = Constants.REDIS_ACTIVITY.FILENAME + "ACTE017" + ":queue:";

    private static ApiStatisticsLogger logger = ApiStatisticsLogger.getInstance();

    @Override
    public JSONObject getActivityAwards(FansActivityDTO fansActivityDTO) {
        Long activityId = fansActivityDTO.getActivityId();
        Long fansId = fansActivityDTO.getFansId();
        if (ObjectUtils.isNotEmpty(fansActivityDTO.getIsLoop()) && 1 == fansActivityDTO.getIsLoop()) {
            // 校验是否有五分钟内的消费异常结果
            String consumeError = RedisUtil.getString(Constants.REDIS_ACTIVITY.FILENAME + activityId + ":consumeError:" + fansId);
            if (ObjectUtils.isNotEmpty(consumeError)) {
                throw new BizException(consumeError);
            }
        }
        ActivityEntity activityEntity = activityService.getById(activityId);
        if (ObjectUtils.isEmpty(activityEntity)) {
            throw new BizException("活动异常，请重试");
        }

        JSONObject json = new JSONObject();
        // 查询活动奖品关联配置
        List<ActivityAwardAndSettingBo> activityAwardList = awardSettingService.getActivityAwardList(activityId, activityEntity.getEndTime().getTime() - DateUtil.date().getTime());
        if (activityAwardList.isEmpty()) {
            throw new BizException("该活动未配置奖品！");
        }
        log.info("活动卡券信息：{}", JSONObject.toJSONString(activityAwardList));

        JSONObject couponA = new JSONObject();
        JSONObject couponB1 = new JSONObject();
        JSONObject couponB2 = new JSONObject();
        JSONObject couponB3 = new JSONObject();
        JSONObject couponC = new JSONObject();
        JSONObject couponD = new JSONObject();
        for (ActivityAwardAndSettingBo a : activityAwardList) {
            if ("A".equals(a.getRemark())) {
                couponA.put("awardId", a.getAwardId());
                couponA.put("awardType", a.getAwardType());
                couponA.put("remark", a.getRemark());
                FansAwardEntity entity = selectOneFansAward(fansId, a);
                log.info("用户领取奖品A券详情信息：{}", JSONObject.toJSONString(entity));
                if (null == entity) {
                    couponA.put("state", 0);
                } else {
                    couponA.put("state", entity.getState());
                    couponA.put("fansAwardId", entity.getFansAwardId());
                    couponA.put("createdAt", entity.getCreatedAt());
                }
                couponA.put("awardAliasName", AmountUtil.convertCent2DollarShort(String.valueOf(a.getAwardPrice())) + "元代金券");
            } else if ("B1".equals(a.getRemark())) {
                couponB1.put("awardId", a.getAwardId());
                couponB1.put("awardType", a.getAwardType());
                couponB1.put("remark", a.getRemark());
                List<FansAwardEntity> awards = fansAwardService.selectListFansAward(fansId, a.getAwardId(), a.getAwardType(), a.getRemark(), "0");
                couponB1.put("num", null == awards || awards.isEmpty() ? 0 : awards.size());
                couponB1.put("awardAliasName", AmountUtil.convertCent2DollarShort(String.valueOf(a.getAwardPrice())) + "元代金券");
            } else if ("B2".equals(a.getRemark())) {
                couponB2.put("awardId", a.getAwardId());
                couponB2.put("awardType", a.getAwardType());
                couponB2.put("remark", a.getRemark());
                FansAwardEntity entity = selectOneFansAward(fansId, a);
                if (null == entity) {
                    couponB2.put("state", 0);
                } else {
                    couponB2.put("state", entity.getState());
                    couponB2.put("fansAwardId", entity.getFansAwardId());
                }
                couponB2.put("awardAliasName", AmountUtil.convertCent2DollarShort(String.valueOf(a.getAwardPrice())) + "元代金券");
            } else if ("B3".equals(a.getRemark())) {
                couponB3.put("awardId", a.getAwardId());
                couponB3.put("awardType", a.getAwardType());
                couponB3.put("remark", a.getRemark());
                FansAwardEntity entity = selectOneFansAward(fansId, a);
                if (null == entity) {
                    couponB3.put("state", 0);
                } else {
                    couponB3.put("state", entity.getState());
                    couponB3.put("fansAwardId", entity.getFansAwardId());
                }
                couponB3.put("awardAliasName", AmountUtil.convertCent2DollarShort(String.valueOf(a.getAwardPrice())) + "元代金券");
            } else if ("C".equals(a.getRemark())) {
                couponC.put("awardId", a.getAwardId());
                couponC.put("awardType", a.getAwardType());
                couponC.put("remark", a.getRemark());
                FansAwardEntity entity = selectOneFansAward(fansId, a);
                if (null == entity) {
                    couponC.put("state", 0);
                } else {
                    couponC.put("state", entity.getState());
                    couponC.put("fansAwardId", entity.getFansAwardId());
                }
                couponC.put("awardAliasName", AmountUtil.convertCent2DollarShort(String.valueOf(a.getAwardPrice())) + "元代金券");
            } else if ("D".equals(a.getRemark())) {
                couponD.put("awardId", a.getAwardId());
                couponD.put("awardType", a.getAwardType());
                couponD.put("remark", a.getRemark());
                LambdaQueryWrapper<FansAwardEntity> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(FansAwardEntity::getFansId, fansId);
                queryWrapper.eq(FansAwardEntity::getAwardId, a.getAwardId());
                queryWrapper.eq(FansAwardEntity::getAwardType, a.getAwardType());
                queryWrapper.eq(FansAwardEntity::getRemark, a.getRemark());
                queryWrapper.orderByDesc(FansAwardEntity::getCreatedAt);
                List<FansAwardEntity> lists = fansAwardService.getBaseMapper().selectList(queryWrapper);
                if (lists.isEmpty()) {
                    couponD.put("state", 0);
                } else {
                    FansAwardEntity entity = lists.get(0);
                    couponD.put("state", entity.getState());
                    couponD.put("fansAwardId", entity.getFansAwardId());
                }
                if (Constants.AWARD.COUPON == a.getAwardType()) {
                    couponD.put("awardAliasName", AmountUtil.convertCent2DollarShort(String.valueOf(a.getAwardPrice())) + "元代金券");
                } else if (Constants.AWARD.GOODS == a.getAwardType()) {
                    couponD.put("awardAliasName", a.getAwardName());
                }
            }
        }
        json.put("A", couponA);
        json.put("B1", couponB1);
        json.put("B2", couponB2);
        json.put("B3", couponB3);
        json.put("C", couponC);
        json.put("D", couponD);
        log.info("用户id：{}，【越减越便宜】用户领取奖品情况：{}", fansId, json.toJSONString());
        return json;
    }

    @Override
    public List<FansAwardEntity> getActivityAwardItems(FansActivityDTO fansActivityDTO) {
        LambdaQueryWrapper<FansAwardEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FansAwardEntity::getAwardId, fansActivityDTO.getAwardId());
        queryWrapper.eq(FansAwardEntity::getAwardType, fansActivityDTO.getAwardType());
        queryWrapper.eq(FansAwardEntity::getFansId, fansActivityDTO.getFansId());
        queryWrapper.eq(FansAwardEntity::getAppId, fansActivityDTO.getAppId());
        queryWrapper.orderByDesc(FansAwardEntity::getCreatedAt);
        return fansAwardService.list(queryWrapper);
    }

    @Override
    public void fansActiveCoupon(FansAwardEntity fansAwardEntity) {
        if ("B1".equals(fansAwardEntity.getRemark())) {
            JSONObject json = JSONObject.parseObject(fansAwardEntity.getExtraJson());
            Long fansId = json.getLong("fansId");//被邀请人ID
            List<FansAwardEntity> fansAwardList = fansAwardService.selectB1CouponAwards(fansId, fansAwardEntity.getFansAwardId());
            log.info("需要失效B1券的客户名单：{}", JSONObject.toJSONString(fansAwardList));
            if (!fansAwardList.isEmpty()) {
                for (FansAwardEntity award : fansAwardList) {
                    award.setState(Constants.FANS_AWARD_STATE.DISABLED);
                    JSONObject failJson = JSONObject.parseObject(award.getExtraJson());
                    failJson.put("failDetail", "对方已被他人转介");
                    award.setExtraJson(failJson.toJSONString());
                    fansAwardService.updateById(award);
                }
            }
        }
    }

    /**
     * 参与活动
     */
    @Override
    public ActivityAwardVO takePartIn(FansActivityDTO fansActivityDTO) {
        log.info("进入越减越便宜升级版活动");
        Long fansId = fansActivityDTO.getFansId();
        Long activityId = fansActivityDTO.getActivityId();

        // 记录请求次数
        ApiStatisticsLogger.getInstance().logRequest("requestCount", 0);

        // 校验是否有五分钟内的消费异常结果
        String consumeError = RedisUtil.getString(Constants.REDIS_ACTIVITY.FILENAME + activityId + ":consumeError:" + fansId);
        if (ObjectUtils.isNotEmpty(consumeError)) {
            throw new BizException(consumeError);
        }

        super.takePartIn(fansActivityDTO);

        // 检测卡券余量
        ActivityAwardVO activityCouponNum = activityAwardService.getActivityCouponNum(activityId);
        if (activityCouponNum.getCouponNum() - activityCouponNum.getCouponGet() < 1) {
            throw new BizException("本次卡券已抢完！");
        }

        // 检测用户参与限制条件
        JSONObject checkJson = activitySettingService.checkActivitySetting(fansEntity, fansActivityDTO.getAppId(), redisOutTime, activityEntity);

        // 查询用户实名信息
        FansAuthEntity fansAuthEntity = fansAuthService.getOne(FansAuthEntity.gw()
                .eq(FansAuthEntity::getAgentNo, fansActivityDTO.getLocationAgentNo())
                .eq(FansAuthEntity::getFansId, fansId));

        // 组装数据
        fansActivityDTO.setActivityEndTime(activityEntity.getEndTime());
        fansActivityDTO.setRedisOutTime(redisOutTime);
        fansActivityDTO.setFansAuthEntity(fansAuthEntity);
        fansActivityDTO.setActivityUserTimesBO(checkJson.getObject("activityUserTimesBO", ActivityUserTimesBO.class));
        fansActivityDTO.setFirstJoin(checkJson.getObject("userJoinScoreValue", Boolean.class));
//        this.check(fansActivityDTO);
        consumeThread.check(fansActivityDTO);
        // 增加用户参与活动记录
        fansActivityService.addFansActivityEntity(fansActivityDTO);
        throw new BizException(ApiCodeEnum.LITE_USER_COUPON, "您正在抢券中，请耐心等待！");
    }

    public void check(FansActivityDTO fansActivityDTO) {
        Long fansId = fansActivityDTO.getFansId();

        String queueKey = queuePrefix + fansId;

        boolean isExist = RedisUtil.setIfAbsent(queueKey, "", 60);
        if (isExist) {
            // 记录消息队列当前排队人数
            Collection<String> keys = RedisUtil.keys(queuePrefix + "*");
            ApiStatisticsLogger.apiStatisticsLogger.info("当前队列中的人数：{}", keys.size());

            // 记录用户加入队列时间
            long joinQueueTime = System.currentTimeMillis();
            fansActivityDTO.setJoinQueueTime(joinQueueTime);
            long userJoinQueueTime = joinQueueTime - fansActivityDTO.getStartTime();
            logger.logRequest("userJoinQueueTime", userJoinQueueTime);

            Acte017SendCouponMQ.MsgPayload msgPayload = new Acte017SendCouponMQ.MsgPayload();
            BeanUtils.copyProperties(fansActivityDTO, msgPayload);
            if (ObjectUtils.isNotEmpty(fansActivityDTO.getActivityUserTimesBO())) {
                Acte017SendCouponMQ.MsgPayload.ActivityUserTimesBO activityUserTimesBO = new Acte017SendCouponMQ.MsgPayload.ActivityUserTimesBO();
                BeanUtils.copyProperties(fansActivityDTO.getActivityUserTimesBO(), activityUserTimesBO);
                msgPayload.setActivityUserTimesBO(activityUserTimesBO);
            }
            if (ObjectUtils.isNotEmpty(fansActivityDTO.getFansEntity())) {
                Acte017SendCouponMQ.MsgPayload.FansAuthEntity fansAuthEntity = new Acte017SendCouponMQ.MsgPayload.FansAuthEntity();
                BeanUtils.copyProperties(fansActivityDTO.getFansEntity(), fansAuthEntity);
                msgPayload.setFansAuthEntity(fansAuthEntity);
            }
            mqSender.send(Acte017SendCouponMQ.build(msgPayload));
        } else {
            log.info("用户fansId：{}已在队列中", fansId);
            throw new BizException(ApiCodeEnum.LITE_USER_COUPON, "卡券正在发放中，请耐心等待！");
        }
    }

    @Override
    @Transactional
    public void handleActivityAwardBO(FansActivityDTO fansActivityDTO) {

        Long fansId = fansActivityDTO.getFansId();
        Long activityId = fansActivityDTO.getActivityId();
        String appId = fansActivityDTO.getAppId();
        String extJson = fansActivityDTO.getExtJson();
        Long redisOutTime = fansActivityDTO.getRedisOutTime();
        Long activityChannelId = fansActivityDTO.getActivityChannelId();
        Date activityEndTime = fansActivityDTO.getActivityEndTime();
        ActivityUserTimesBO activityUserTimesBO = fansActivityDTO.getActivityUserTimesBO();
        Boolean firstJoin = fansActivityDTO.getFirstJoin();
        FansAuthEntity fansAuthEntity = fansActivityDTO.getFansAuthEntity();

        AgentInfoEntity agentInfoEntity = agentInfoService.getAgentInfo(fansActivityDTO.getLocationAgentNo());

        // 获取活动奖品
        List<ActivityAwardAndSettingBo> activityAwardList = awardSettingService.getActivityAwardList(activityId, redisOutTime);

        log.info("活动奖品详细信息:{}", JSONUtil.toJsonStr(activityAwardList));

        // 校验用户奖品限制
        Map<Long, JSONObject> awardUserTimesJsonMap = new HashMap<>();
        for (ActivityAwardAndSettingBo activityAwardAndSettingBo : activityAwardList) {
            JSONObject awardUserTimesJson = awardSettingService.AwardSettingRule(fansId, fansActivityDTO.getLocationAgentNo(), activityAwardAndSettingBo);
            if (ObjectUtils.isNotEmpty(awardUserTimesJson)) {
                awardUserTimesJsonMap.put(activityAwardAndSettingBo.getAwardId(), awardUserTimesJson);
            }
        }

        // 发放A奖品
        activityAwardList.stream().filter(item -> "A".equals(item.getRemark())).forEach(
                item -> {
                    log.info("用户fansId：{},发放{}卡券", fansId, item.getRemark());
                    sendAwardService.sendCouponOrGoods(fansId, appId, item, item.getPayAuthId(), activityChannelId, true, extJson);

                    JSONObject awardUserTimesJson = awardUserTimesJsonMap.get(item.getAwardId());
                    awardSettingService.updateAwardLimitCache(awardUserTimesJson, redisOutTime);
                }
        );

        // 发放B3券
        // 判断用户是否实名
        log.info("发放B3券前，用户实名信息：{}", JSONUtil.toJsonStr(fansAuthEntity));
        if (ObjectUtils.isEmpty(fansAuthEntity) || ObjectUtils.isEmpty(fansAuthEntity.getCstmNo())) {
            boolean isJoinRealNameAuth = fansAwardService.isJoinRealNameAuth(fansId, fansActivityDTO.getLocationAgentNo());
            if (isJoinRealNameAuth) {
                log.info("用户fansId：{},已参加过同类型的实名认证活动,不再发放该类奖品", fansId);
            } else {
                activityAwardList.stream().filter(item -> "B3".equals(item.getRemark())).forEach(
                        item -> {
                            log.info("用户fansId：{},发放{}卡券", fansId, item.getRemark());
                            sendAwardService.sendActivateAward(fansId, appId, item.getAwardId(), item.getAwardType(),
                                    activityEndTime, item.getRemark(), activityChannelId, Constants.FANS_AWARD_TAG.REAL_NAME_AUTH,
                                    "{\"templateNo\":\"ACTE017\"}", agentInfoEntity);
                        }
                );
            }
        }
        // 发放C券
        activityAwardList.stream().filter(item -> "C".equals(item.getRemark())).forEach(
                item -> {
                    log.info("用户fansId：{},发放{}卡券", fansId, item.getRemark());
                    LambdaQueryWrapper<FansAwardEntity> queryWrapper = new LambdaQueryWrapper<>();
                    queryWrapper.eq(FansAwardEntity::getFansId, fansId);
                    queryWrapper.eq(FansAwardEntity::getAwardId, item.getAwardId());
                    queryWrapper.eq(FansAwardEntity::getAwardType, item.getAwardType());
                    queryWrapper.eq(FansAwardEntity::getState, Constants.FANS_AWARD_STATE.ACTIVATE);
                    List<FansAwardEntity> fansAwards = fansAwardService.list(queryWrapper);
                    if (null == fansAwards || fansAwards.isEmpty()) {
                        sendAwardService.sendActivateAward(fansId, appId, item.getAwardId(), item.getAwardType(),
                                activityEndTime, item.getRemark(), activityChannelId, null, null, agentInfoEntity);
                    }
                }
        );
        // 发放D券
        activityAwardList.stream().filter(item -> "D".equals(item.getRemark())).forEach(
                item -> {
                    log.info("用户fansId：{},发放{}卡券", fansId, item.getRemark());
                    LambdaQueryWrapper<FansAwardEntity> queryWrapper = new LambdaQueryWrapper<>();
                    queryWrapper.eq(FansAwardEntity::getFansId, fansId);
                    queryWrapper.eq(FansAwardEntity::getAwardId, item.getAwardId());
                    queryWrapper.eq(FansAwardEntity::getAwardType, item.getAwardType());
                    queryWrapper.eq(FansAwardEntity::getState, Constants.FANS_AWARD_STATE.ACTIVATE);
                    List<FansAwardEntity> fansAwards = fansAwardService.list(queryWrapper);
                    if (null == fansAwards || fansAwards.size() < 1) {
                        sendAwardService.sendActivateAward(fansId, appId, item.getAwardId(), item.getAwardType(),
                                activityEndTime, item.getRemark(), activityChannelId, null, null, agentInfoEntity);
                    }
                }
        );
        RedisUtil.del(String.format("%s%s:%s", Constants.REDIS_ACTIVITY.FILENAME, activityId, Constants.REDIS_ACTIVITY.NUMBER));

        //重新放置活动奖品配置缓存
        if (!activityAwardList.isEmpty()) {
            String activityAwardKey = String.format("%s%s:%s", Constants.REDIS_ACTIVITY.FILENAME, fansActivityDTO.getActivityId(), Constants.REDIS_ACTIVITY.AWARD);
            RedisUtil.set(activityAwardKey, activityAwardList, redisOutTime, TimeUnit.MILLISECONDS);
            log.info("活动奖品列表，修改奖品中的当前周期性领取次数数据，redisKey:{},redisValue:{},redisOutTime:{},TimeUnit:{}", activityAwardKey, JSONUtil.toJsonStr(activityAwardList), redisOutTime, "TimeUnit.MILLISECONDS");
        }

        String currentTimesKey = String.format("%s%s:%s%s", Constants.REDIS_ACTIVITY.FILENAME, activityId, Constants.REDIS_ACTIVITY.USER_FILENAME, fansId);
        RedisUtil.set(currentTimesKey, activityUserTimesBO, redisOutTime, TimeUnit.MILLISECONDS);
        log.info("更新个人参与次数的Redis数据,redisKey:{},redisValue:{},redisOutTime:{},TimeUnit:{}", currentTimesKey, JSONUtil.toJsonStr(activityUserTimesBO), redisOutTime, "TimeUnit.MILLISECONDS");
        if (firstJoin != null) {
            //用户参与福分奖励redis缓存key
            String userJoinScoreKey = String.format("%s%s:%s%s", Constants.REDIS_ACTIVITY.FILENAME, fansActivityDTO.getActivityId(), Constants.REDIS_ACTIVITY.USER_JOIN_SCORE, fansId);
            RedisUtil.set(userJoinScoreKey, firstJoin, redisOutTime, TimeUnit.MILLISECONDS);
        }
        String queueKey = queuePrefix + fansId;
        RedisUtil.del(queueKey);
    }

    /**
     * 查询用户领取的最后一张卡券
     *
     * @param fansId
     * @param activityAwardAndSettingBo
     * @return
     */
    public FansAwardEntity selectOneFansAward(Long fansId, ActivityAwardAndSettingBo activityAwardAndSettingBo) {
        LambdaQueryWrapper<FansAwardEntity> gw = FansAwardEntity.gw().eq(FansAwardEntity::getFansId, fansId)
                .eq(FansAwardEntity::getAwardId, activityAwardAndSettingBo.getAwardId())
                .eq(FansAwardEntity::getAwardType, activityAwardAndSettingBo.getAwardType())
                .eq(FansAwardEntity::getRemark, activityAwardAndSettingBo.getRemark())
                .orderByDesc(FansAwardEntity::getCreatedAt)
                .last("limit 1");
        return fansAwardService.getOne(gw);
    }

    /**
     * 获取越减越便宜 到当前为止开展的数量
     * @return
     */
    public long getCount() {
        return activityService.count(
                new QueryWrapper<ActivityEntity>()
                        .eq("activity_template_no", "ACTE017")
        );
    }

//    /**
//     * 越减越便宜客户参与记录明细 查询
//     *
//     * @param iPage
//     * @param activityAwardDTO
//     * @return
//     */
//    public IPage<StatActe017RecordVO> getFansRecord(IPage iPage, ActivityAwardDTO activityAwardDTO) {
//        return this.statActe017RecordMapper.getFansRecord(iPage, activityAwardDTO);
//    }
//
//    /**
//     * 越减越便宜客户参与记录明细 导出
//     *
//     * @param activityAwardDTO
//     * @return
//     */
//    public void exportFansRecord(ActivityAwardDTO activityAwardDTO) {
//
//        List<StatActe017RecordVO> fansRecordList = statActe017RecordMapper.getFansRecord(activityAwardDTO);
//        if (CollUtil.isEmpty(fansRecordList)) {
//            log.info("没有数据");
//            throw new BizException("无数据可导出");
//        }
//        String fileName = "越减越便宜客户参与记录明细表--截至" + DateUtil.format(new Date(), DatePattern.CHINESE_DATE_PATTERN);
//        // 添加导出任务记录
//        Long exportTaskId = this.sysExportTaskService.addExportTask(
//                GzUserDetails.getCurrentUserDetails().getSysUser(),
//                fileName,
//                Constants.EXPORT_TASK_ENUM.REQUEST_CODE.FANS_PARTICIPATION_RECORD,
//                Constants.EXPORT_TASK_ENUM.RESOURCE_TYPE.FANS,
//                JSONUtil.toJsonStr(activityAwardDTO)
//        );
//        // 发送mq
//        mqSender.send(ExportExcelMQ.build(exportTaskId));
//    }
//
//    public void exportAgentDetail(ActivityAwardDTO activityAwardDTO) {
//        List<StatActe017NumVO> actAgentDetaiList = statActe017NumService.getActAgentDetaiList(activityAwardDTO);
//        if (CollUtil.isEmpty(actAgentDetaiList)) {
//            log.info("没有数据");
//            throw new BizException("无数据可导出");
//        }
//        String fileName = "越减越便宜机构明细表--截至" + DateUtil.format(new Date(), DatePattern.CHINESE_DATE_PATTERN);
//        // 添加导出任务记录
//        Long exportTaskId = this.sysExportTaskService.addExportTask(
//                GzUserDetails.getCurrentUserDetails().getSysUser(),
//                fileName,
//                Constants.EXPORT_TASK_ENUM.REQUEST_CODE.AGENT_DETAIL,
//                Constants.EXPORT_TASK_ENUM.RESOURCE_TYPE.FANS,
//                JSONUtil.toJsonStr(activityAwardDTO)
//        );
//        // 发送mq
//        mqSender.send(ExportExcelMQ.build(exportTaskId));
//    }
}
